<template>
  <div>
    <el-row :gutter="20">
      <el-col :span="8">
        <el-input
          v-model="search.jobName"
          placeholder="请输入岗位名称"
          size="normal"
          clearable
        ></el-input>
      </el-col>
      <el-col :span="8">
        <el-select
          v-model="search.lv1"
          placeholder="请选择分类进行筛选"
          clearable
        >
          <el-option
            v-for="item in cateList"
            :key="item.objectId"
            :label="item.name"
            :value="item.name"
          >
          </el-option>
        </el-select>
      </el-col>
      <el-col :span="8">
        <el-button type="primary" size="default" @click="handleSearch"
          >查询</el-button
        >
      </el-col>
    </el-row>

    <el-table :data="tableData" style="width: 100%" row-key="objectId">
      <el-table-column label="岗位名称" width="180" prop="jobName">
      </el-table-column>
      <el-table-column label="城市" prop="cityName"> </el-table-column>
      <el-table-column label="薪资待遇" prop="salaryDesc" />
      <el-table-column label="分类" prop="lv1" />
      <el-table-column label="学历要求" prop="jobDegree" />
      <el-table-column label="经验要求" prop="jobExperience" />
      <el-table-column label="操作">
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="small"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="page-cont">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="total"
        @current-change="handleChange"
      />
    </div>
  </div>
</template>

<script>
import { categoryGet, jobGet } from "@/api/job.js";
export default {
  data() {
    return {
      tableData: [],
      total: 0,
      cateList: [],
      search: {
        jobName: "",
        lv1: "",
      },
    };
  },
  created() {
    jobGet().then((res) => {
      console.log(res);
      let { results, count } = res.data;
      this.tableData = results;
      this.total = count;
    });

    categoryGet().then((res) => {
      this.cateList = res.data.results;
    });
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    handleSearch() {
      jobGet(1, { ...this.search }).then((res) => {
        console.log(res);
        let { results, count } = res.data;
        this.tableData = results;
        this.total = count;
      });
    },
    handleChange(page) {
      console.log(page);
      jobGet(page, { ...this.search }).then((res) => {
        console.log(res);
        let { results } = res.data;
        this.tableData = results;
      });
    },
  },
};
</script>
<style lang="scss">
.page-cont {
  margin-top: 30px;
  text-align: right;
  display: flex;
  justify-content: end;
}
</style>
